/*
 * File     : LibraryRecord.java
 * Created  : 10 Oct 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.internal.library;


/**
 * <p>
 *  Encapsulates information about a libray.
 * </p>
 *
 * @author Matthew Wilson
 */
public final class LibraryRecord
{

    /**
     * Marker value when a library implementation is being created.
     */
    public static final LibraryRecord IN_PROGRESS = new LibraryRecord();

    private final Class< ? > type;

    private final Object library;

    private final String implName;

    /**
     * @param type
     *            the interface type
     * @param library
     *            the library instance
     * @param implName
     *            the implementation type name (byte-code style)
     */
    public LibraryRecord( final Class< ? > type,
                          final Object library,
                          final String implName )
    {
        this.type = type;
        this.library = type.cast( library );
        this.implName = implName;
    }

    /**
     * Creates a new marker instance.
     */
    private LibraryRecord()
    {
        this.type = null;
        this.library = null;
        this.implName = null;
    }

    /**
     * @return the interface type
     */
    public Class< ? > getType()
    {
        return this.type;
    }

    /**
     * @return the library
     */
    public Object getLibrary()
    {
        return this.library;
    }

    /**
     * @return the implementation type name (byte-code style)
     */
    public String getImplName()
    {
        return this.implName;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString()
    {
        if ( this.type == null )
        {
            return "In progress";
        }
        return "[" + this.type.getName() + ", "
                   + this.implName + "]";
    }

}
